home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / mui / muibuilder / mb / gcc / source / gencodegcc.c < prev    next >
C/C++ Source or Header  |  1995-05-25  |  22KB  |  853 lines

  1.  
  2. #include "gencodegcc.h"
  3.  
  4. char *version = "$VER: GenCodeGCC 2.2 (" __DATE__ " by D.-M. Brosig)";
  5.  
  6. struct Library * MUIBBase = NULL;
  7.  
  8. /* Global variables */
  9. ULONG    varnb;            /* number of variables */
  10.  
  11. BOOL    Code, Env;        /* flags-options */
  12. BOOL    Locale, Declarations;
  13. BOOL    Notifications;
  14. BOOL    ExternalExist = FALSE;
  15. char    *FileName, *CatalogName;/* Strings */
  16. char    *GetString;
  17. char    *GetMBString;
  18.  
  19. FILE    *file;
  20.  
  21. char    HeaderFile[512];
  22. char    GUIFile[512];
  23. char    MBDir[512];
  24. char    Externals[512];
  25. char    Main[512];
  26.  
  27. /* variable types */
  28. char    *STR_type[] = {
  29.   "BOOL",
  30.   "int",
  31.   "char *",
  32.   "char *",
  33.   "APTR",
  34.   "",
  35.   "",
  36.   "",
  37.   "APTR",
  38.   "APTR"
  39. };                          
  40.  
  41. void MB_Get(Tag Tag1, ...)
  42. {
  43.   MB_GetA( (struct TagItem *) ((ULONG) &Tag1) );
  44. }
  45.  
  46. void MB_GetVarInfo(ULONG type, Tag Tag1, ...)
  47. {
  48.   MB_GetVarInfoA(type, (struct TagItem *) ((ULONG) &Tag1) );
  49. }
  50.  
  51. void Indent(int nb)
  52. {
  53.   int    i;
  54.  
  55.   for(i=0;i<nb;i++) fprintf(file, "\t");
  56. }
  57.  
  58. void WriteParameters(void)
  59. {
  60.   int   i;
  61.   char  *varname, *typename;
  62.   ULONG type,size;
  63.   BOOL  comma = FALSE;
  64.   
  65.   typename = STR_type[ TYPEVAR_EXTERNAL_PTR - 1 ];
  66.   if (Notifications)
  67.     for(i=0;i<varnb;i++)
  68.     {
  69.       MB_GetVarInfo (i, MUIB_VarType, &type,
  70.                 MUIB_VarName, &varname,
  71.                 MUIB_VarSize, &size,
  72.                 TAG_END);
  73.       if (type == TYPEVAR_EXTERNAL_PTR)
  74.       {
  75.     if (comma) fprintf(file, ", ");
  76.     comma = TRUE;
  77.     fprintf(file, "%s %s", typename, varname);
  78.       }
  79.     }
  80.   if (!comma) fprintf(file, "void");
  81. }
  82.  
  83. void WriteDeclarations(int vartype)
  84. {
  85.   int    i;
  86.   char    *varname;
  87.   ULONG    type, size;
  88.   char    *typename;
  89.   int    nb_ident = 1;
  90.   char    buffer[150];
  91.     
  92.   typename = STR_type[ vartype - 1 ];        /* find the name 'BOOL ...'    */
  93.   buffer[0] = '\0';
  94.   for(i=0;i<varnb;i++)
  95.   {
  96.     MB_GetVarInfo (i,MUIB_VarType, &type,
  97.              MUIB_VarName, &varname,
  98.              MUIB_VarSize, &size,
  99.              TAG_END);
  100.     if (type == vartype)
  101.       switch(type)
  102.       {
  103.     case TYPEVAR_TABSTRING:    fprintf(file, "\t%s\t%s[%d];\n",
  104.                      typename,varname,size+1);
  105.                 break;
  106.     case TYPEVAR_IDENT:    fprintf(file,"#define %s %d\n", varname, nb_ident++);
  107.                 break;
  108.     case TYPEVAR_LOCAL_PTR:    if (strlen(buffer)==0) 
  109.                   sprintf(buffer, "\t%s\t%s", typename, varname);
  110.                 else
  111.                 {
  112.                   strcat(buffer, ", ");
  113.                   strcat(buffer, varname);
  114.                 }
  115.                 if (strlen(buffer)>=70)
  116.                 {
  117.                   strcat(buffer, ";\n");
  118.                   fprintf(file, "%s", buffer);
  119.                   buffer[0] = '\0';
  120.                 }
  121.                 break;
  122.     default:
  123.                 fprintf(file, "\t%s\t%s;\n",typename, varname);
  124.                 break;
  125.     }
  126.   }
  127.   if (strlen(buffer)>0) fprintf(file, "%s;\n", buffer);
  128. }
  129.  
  130. void WriteInitialisations(int vartype)
  131. {
  132.   int    i, j;
  133.   ULONG    type, size;
  134.   char    *inits, *name;
  135.   BOOL    enter = FALSE;
  136.  
  137.   for(i=0;i<varnb;i++)
  138.   {
  139.     MB_GetVarInfo(i,MUIB_VarType    , &type,
  140.             MUIB_VarName    , &name,
  141.             MUIB_VarSize    , &size,
  142.                 MUIB_VarInitPtr    , &inits,
  143.             TAG_END);
  144.     if (type == vartype)
  145.     {
  146.       enter = TRUE;
  147.       switch(type)
  148.       {
  149.     case TYPEVAR_TABSTRING:    for(j=0;j<size;j++)
  150.                 {
  151.                   if (!Locale) 
  152.                     fprintf(file, "\tMBObj->%s[%d] = \"%s\";\n", name, j, inits);
  153.                   else
  154.                     fprintf(file, "\tMBObj->%s[%d] = %s(%s);\n", name, j, GetMBString, inits);
  155.                   inits = inits + strlen(inits) + 1;
  156.                 }
  157.                 fprintf(file, "\tMBObj->%s[%d] = NULL;\n", name, j);
  158.                 break;
  159.     case TYPEVAR_STRING:     if (*inits != 0)
  160.                 {
  161.                   if (!Locale) 
  162.                     fprintf(file, "\tMBObj->%s = \"%s\";\n", name, inits);
  163.                   else
  164.                     fprintf(file, "\tMBObj->%s = %s(%s);\n", name, GetMBString, inits);
  165.                 }
  166.                 else
  167.                   fprintf(file, "\tMBObj->%s = NULL;\n", name);
  168.                 break;
  169.     case TYPEVAR_HOOK:    fprintf(file, "\tstatic const struct Hook %sHook = { {NULL, NULL}, (HOOKFUNC) %s, NULL, NULL};\n", name, name);
  170.                 break;
  171.     default:        break;
  172.       }
  173.     }
  174.   }
  175.   if (enter) fprintf(file, "\n");
  176. }
  177.  
  178. void WriteCode(void)
  179. {
  180.   ULONG    type;
  181.   char*    code;
  182.   BOOL    InFunction     = FALSE;
  183.   BOOL    IndentFunction = TRUE;
  184.   BOOL    obj_function;
  185.   BOOL    InObj;
  186.   int    nb_indent      = 1;
  187.   int    nb_function    = 0;
  188.   int    name;
  189.  
  190.   extern void End(void);
  191.  
  192.   MB_GetNextCode(&type, &code);
  193.   while(type != -1)
  194.   {
  195.     switch(type)
  196.     {
  197.       case TC_CREATEOBJ:
  198.             name = atoi(code);
  199.             fprintf(file, "%s,\n",MUIStrings[name]);
  200.             nb_indent++;
  201.             IndentFunction = TRUE;
  202.             MB_GetNextCode(&type, &code);
  203.             InObj = TRUE;
  204.             break;
  205.       case TC_ATTRIBUT:
  206.             Indent(nb_indent);
  207.             name = atoi(code);
  208.             fprintf(file, "%s, ",MUIStrings[name]);
  209.             IndentFunction = FALSE;
  210.             MB_GetNextCode(&type, &code);
  211.             break;
  212.       case TC_END:
  213.             nb_indent--;
  214.             InObj = FALSE;
  215.             Indent(nb_indent);
  216.             name = atoi(code);
  217.             fprintf(file, "%s",MUIStrings[name]);
  218.             IndentFunction = TRUE;
  219.             MB_GetNextCode(&type, &code);
  220.             fprintf(file, ";\n\n");
  221.             break;
  222.       case TC_MUIARG_OBJFUNCTION:
  223.             if (IndentFunction) Indent(nb_indent);
  224.             nb_function++;
  225.             name = atoi(code);
  226.             fprintf(file, "%s(",MUIStrings[name]);
  227.             IndentFunction = FALSE;
  228.             InFunction     = TRUE;
  229.             MB_GetNextCode(&type, &code);
  230.             obj_function = TRUE;
  231.             InFunction = TRUE;
  232.             break;
  233.       case TC_MUIARG_FUNCTION:
  234.       case TC_FUNCTION:
  235.             if (IndentFunction) Indent(nb_indent);
  236.             nb_function++;
  237.             name = atoi(code);
  238.             fprintf(file, "%s(",MUIStrings[name]);
  239.             IndentFunction = FALSE;
  240.             InFunction     = TRUE;
  241.             MB_GetNextCode(&type, &code);
  242.             obj_function = FALSE;
  243.             break;
  244.       case TC_OBJFUNCTION:
  245.             if (IndentFunction) Indent(nb_indent);
  246.             nb_function++;
  247.             name = atoi(code);
  248.             fprintf(file, "%s(",MUIStrings[name]);
  249.             InFunction     = TRUE;
  250.             IndentFunction = FALSE;
  251.             MB_GetNextCode(&type,&code);
  252.             obj_function = TRUE;
  253.             break;
  254.       case TC_STRING:
  255.             fprintf(file, "\"%s\"",code);
  256.             MB_GetNextCode(&type, &code);
  257.             IndentFunction = TRUE;
  258.             if (InFunction)
  259.             {
  260.               if (type  != TC_END_FUNCTION) 
  261.                 fprintf(file, ", ");
  262.               IndentFunction = FALSE;
  263.             }
  264.             else
  265.               fprintf(file, ",\n");
  266.             break;
  267.       case TC_LOCALESTRING:
  268.             fprintf(file, "%s(%s)",GetMBString, code);
  269.                         MB_GetNextCode(&type, &code);
  270.                         IndentFunction = TRUE;
  271.                         if (InFunction)
  272.                         {
  273.                           if (type  != TC_END_FUNCTION) 
  274.                             fprintf(file, ", ");
  275.                           IndentFunction = FALSE;
  276.                         }
  277.                         else
  278.                           fprintf(file, ",\n");
  279.                         break;
  280.       case TC_LOCALECHAR:
  281.             fprintf(file, "%s(%s)[0]",GetString, code);
  282.                         MB_GetNextCode(&type, &code);
  283.                         IndentFunction = TRUE;
  284.                         if (InFunction)
  285.                         {
  286.                           if (type  != TC_END_FUNCTION) 
  287.                             fprintf(file, ", ");
  288.                           IndentFunction = FALSE;
  289.                         }
  290.                         else
  291.                           fprintf(file, ",\n");
  292.                         break;
  293.       case TC_INTEGER:
  294.             fprintf(file, "%s", code);
  295.                         MB_GetNextCode(&type, &code);
  296.                         IndentFunction = TRUE;
  297.                         if (InFunction)
  298.                         {
  299.                           if (type  != TC_END_FUNCTION) 
  300.                             fprintf(file, ", ");
  301.                           IndentFunction = FALSE;
  302.                         }
  303.                         else
  304.                           fprintf(file, ",\n");
  305.                         break;
  306.       case TC_CHAR:
  307.             fprintf(file, "'%s'",code);
  308.                         MB_GetNextCode(&type, &code);
  309.                         IndentFunction = TRUE;
  310.                         if (InFunction)
  311.                         {
  312.                           if (type  != TC_END_FUNCTION)
  313.                             fprintf(file, ", ");
  314.                           IndentFunction = FALSE;
  315.                         }
  316.                         else
  317.                           fprintf(file, ",\n");
  318.                         break;    
  319.       case TC_VAR_AFFECT:
  320.             name = atoi(code);
  321.             MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  322.             if ((type == TYPEVAR_LOCAL_PTR) || (type == TYPEVAR_EXTERNAL_PTR))
  323.               fprintf( file, "\t%s = ", code);
  324.             else 
  325.               fprintf(file, "\tMBObj->%s = ", code); 
  326.             IndentFunction = FALSE;
  327.             MB_GetNextCode(&type, &code);
  328.             break;
  329.       case TC_OBJ_ARG:
  330.       case TC_VAR_ARG:
  331.             name = atoi(code);
  332.             MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  333.             if ((type == TYPEVAR_LOCAL_PTR) || (type == TYPEVAR_EXTERNAL_PTR))
  334.               fprintf(file, "%s", code);
  335.             else
  336.               fprintf(file, "MBObj->%s", code);
  337.             MB_GetNextCode(&type, &code);
  338.             if ((InFunction)&&(type != TC_END_FUNCTION)) 
  339.               fprintf(file, ", ");
  340.             if (!InFunction)
  341.             {
  342.               fprintf(file, ",\n");
  343.               IndentFunction = TRUE;
  344.             }
  345.             break;
  346.       case TC_END_FUNCTION:
  347.             MB_GetNextCode(&type, &code);
  348.             if (nb_function>1)
  349.             {
  350.               if (type != TC_END_FUNCTION) 
  351.                 fprintf(file, "),");
  352.               else
  353.                 fprintf(file, ")");
  354.             }    
  355.             else
  356.             {
  357.               if (obj_function) 
  358.                 fprintf(file, ");\n\n");
  359.               else
  360.                 fprintf(file, "),\n");
  361.               IndentFunction = TRUE;
  362.               InFunction     = FALSE;
  363.               obj_function   = FALSE;
  364.             }
  365.             nb_function--;
  366.             break;
  367.       case TC_BOOL:
  368.             if (*code == '0')
  369.               fprintf(file, "FALSE");
  370.             else
  371.               fprintf(file, "TRUE" );
  372.             MB_GetNextCode(&type, &code);
  373.             if (InFunction)
  374.             {
  375.               if (type != TC_END_FUNCTION)
  376.               {
  377.                 fprintf(file, ", ");
  378.                 IndentFunction = FALSE;
  379.               }
  380.             }
  381.             else
  382.               fprintf(file, ",\n");
  383.             break;
  384.        case TC_MUIARG:
  385.             if (IndentFunction) Indent(nb_indent);
  386.             name = atoi(code);
  387.             fprintf(file, "%s", MUIStrings[name]);
  388.             MB_GetNextCode(&type, &code);
  389.             if (InFunction)
  390.             {
  391.               if (type != TC_END_FUNCTION)
  392.               {
  393.                 fprintf(file, ", ");
  394.                 IndentFunction = FALSE;
  395.               }
  396.             }
  397.             else
  398.             {
  399.               fprintf(file, ",\n");
  400.               IndentFunction = TRUE;
  401.             }
  402.             break;
  403.       case TC_MUIARG_ATTRIBUT:
  404.             if (IndentFunction) Indent(nb_indent);
  405.             name = atoi(code);
  406.             MB_GetNextCode(&type, &code);
  407.             if (InObj)
  408.               fprintf(file, "%s,\n", MUIStrings[name]);
  409.             else
  410.             {
  411.               if (InFunction)
  412.               {
  413.                 if (type != TC_END_FUNCTION)
  414.                   fprintf(file, "%s,", MUIStrings[name]);
  415.                 else
  416.                   fprintf(file, "%s", MUIStrings[name]);
  417.               }
  418.               else
  419.               {
  420.                 fprintf(file, "%s;\n\n", MUIStrings[name]);
  421.               }
  422.             }
  423.             break;
  424.       case TC_MUIARG_OBJ:
  425.             if (IndentFunction) Indent(nb_indent);
  426.             name = atoi(code);
  427.             MB_GetNextCode(&type, &code);
  428.             fprintf(file, "%s;\n\n", MUIStrings[name]);
  429.             break;
  430.       case TC_EXTERNAL_FUNCTION:
  431.             fprintf(file, "&%sHook", code);
  432.             MB_GetNextCode(&type, &code);
  433.             if (InFunction)
  434.             {
  435.               if (type != TC_END_FUNCTION)    
  436.               {
  437.                 fprintf(file, ", ");
  438.                 IndentFunction = FALSE;
  439.               }
  440.             }
  441.             else
  442.             {
  443.               fprintf(file, ",\n");
  444.               IndentFunction = TRUE;
  445.             }
  446.             break;
  447.       default:
  448.             printf("Type = %d\n", type);
  449.             printf("ERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n");
  450.             End();
  451.             exit(1);
  452.             break;
  453.     }
  454.   }
  455. }
  456.  
  457. void WriteNotify(void)
  458. {
  459.   ULONG    type;
  460.   char*    code;
  461.   int    name;
  462.   BOOL    indent = FALSE;
  463.  
  464.   extern void End(void);
  465.  
  466.   fprintf(file, "\n");
  467.   MB_GetNextNotify(&type, &code);
  468.   while(type != -1)
  469.   {
  470.     if (indent) fprintf(file, "\t\t");
  471.     indent = TRUE;
  472.     switch(type)
  473.     {
  474.       case TC_END_FUNCTION:
  475.       case TC_END_NOTIFICATION:
  476.             fprintf(file, ");\n\n");
  477.             MB_GetNextNotify(&type, &code);
  478.             indent = FALSE;
  479.             break;
  480.       case TC_BEGIN_NOTIFICATION:
  481.             name = atoi(code);
  482.             MB_GetVarInfo(name, MUIB_VarName, &code, TAG_END);
  483.             if ((type == TYPEVAR_LOCAL_PTR) || (type == TYPEVAR_EXTERNAL_PTR))
  484.                 fprintf(file, "\tDoMethod((Object *) %s,\n", code);
  485.             else  
  486.               fprintf(file, "\tDoMethod((Object *) MBObj->%s,\n", code);
  487.             MB_GetNextNotify(&type, &code);
  488.             break;
  489.       case TC_FUNCTION:
  490.             name = atoi(code);
  491.             fprintf(file, "\t%s(", MUIStrings[name]);
  492.             MB_GetNextNotify(&type, &code);
  493.             indent = FALSE;
  494.             break;
  495.       case TC_STRING:
  496.             fprintf(file, "\"%s\"",code);
  497.             MB_GetNextNotify(&type, &code);
  498.             if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  499.               fprintf(file, ",\n");
  500.             else 
  501.               fprintf(file, "\n");
  502.             break;
  503.       case TC_LOCALESTRING:
  504.             fprintf(file, "%s(%s)",GetMBString, code);
  505.                         MB_GetNextNotify(&type, &code);
  506.                         if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION)) 
  507.                           fprintf(file, ",\n");
  508.             else 
  509.               fprintf(file, "\n");
  510.                         break;
  511.       case TC_LOCALECHAR:
  512.             fprintf(file, "%s(%s)[0]\n",GetString, code);
  513.                         MB_GetNextNotify(&type, &code);
  514.                         if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  515.                           fprintf(file, ",\n");
  516.             else 
  517.               fprintf(file, "\n");
  518.                         break;
  519.       case TC_INTEGER:
  520.             fprintf(file, "%s", code);
  521.                         MB_GetNextNotify(&type, &code);
  522.                         if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  523.                           fprintf(file, ",\n");
  524.             else 
  525.               fprintf(file, "\n");
  526.                         break;
  527.       case TC_CHAR:
  528.             fprintf(file, "'%s'",code);
  529.                         MB_GetNextNotify(&type, &code);
  530.                         if ((type  != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  531.                           fprintf(file, ",\n");
  532.             else 
  533.               fprintf(file, "\n");
  534.                         break;    
  535.       case TC_OBJ_ARG:
  536.       case TC_VAR_ARG:
  537.             name = atoi(code);
  538.             MB_GetVarInfo(name, MUIB_VarName, &code, MUIB_VarType, &type, TAG_END);
  539.             if ((type == TYPEVAR_LOCAL_PTR) || (type == TYPEVAR_EXTERNAL_PTR))
  540.                 fprintf(file, "%s", code);
  541.             else  
  542.               fprintf(file, "MBObj->%s", code);
  543.             MB_GetNextNotify(&type, &code);
  544.             if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  545.               fprintf(file, ",\n");
  546.             else 
  547.               fprintf(file, "\n");
  548.             break;
  549.       case TC_BOOL:
  550.             if (*code == '0')
  551.               fprintf(file, "FALSE");
  552.             else
  553.               fprintf(file, "TRUE" );
  554.             MB_GetNextNotify(&type, &code);
  555.             if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  556.               fprintf(file, ",\n");
  557.             else 
  558.               fprintf(file, "\n");
  559.             break;
  560.       case TC_MUIARG:
  561.       case TC_MUIARG_OBJ:
  562.             name = atoi(code);
  563.             fprintf(file, "%s", MUIStrings[name]);
  564.             MB_GetNextNotify(&type, &code);
  565.             if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  566.               fprintf(file, ", ");
  567.             indent = FALSE;
  568.             break;
  569.       case TC_MUIARG_ATTRIBUT:
  570.             name = atoi(code);
  571.             fprintf(file, "%s", MUIStrings[name]);
  572.             MB_GetNextNotify(&type, &code);
  573.             if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  574.               fprintf(file, ",\n");
  575.             else 
  576.               fprintf(file, "\n");
  577.             break;
  578.       case TC_EXTERNAL_CONSTANT:
  579.                         fprintf(file, "%s", code);
  580.                         MB_GetNextNotify(&type, &code);
  581.                         if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  582.                           fprintf(file, ",\n");
  583.             else 
  584.               fprintf(file, "\n");
  585.                         break;
  586.       case TC_EXTERNAL_FUNCTION:
  587.             fprintf(file, "&%sHook", code);
  588.             MB_GetNextNotify(&type, &code);
  589.                         if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  590.                           fprintf(file, ",\n");
  591.             else 
  592.               fprintf(file, "\n");
  593.             break;
  594.       case TC_EXTERNAL_VARIABLE:
  595.             fprintf(file, "%s", code);
  596.             MB_GetNextNotify(&type, &code);
  597.                         if ((type != TC_END_NOTIFICATION)&&(type != TC_END_FUNCTION))
  598.                           fprintf(file, ",\n");
  599.             else 
  600.               fprintf(file, "\n");
  601.             break;
  602.       default:
  603.             printf("Type = %d\n", type);
  604.             printf("ERROR !!!!! THERE IS A PROBLEM WITH THIS FILE !!!\n");
  605.             End();
  606.             exit(1);
  607.             break;
  608.     }
  609.   }
  610. }
  611.  
  612. void Init(void)
  613. {
  614.   BPTR    lock;
  615.  
  616.   /* Get all needed variables */
  617.   MB_Get(MUIB_VarNumber        , &varnb,
  618.     MUIB_Code        , &Code,
  619.     MUIB_Environment    , &Env,
  620.     MUIB_Locale        , &Locale,
  621.     MUIB_Notifications    , &Notifications,
  622.     MUIB_Declarations    , &Declarations,
  623.     MUIB_FileName        , &FileName,
  624.     MUIB_CatalogName    , &CatalogName,
  625.     MUIB_GetStringName    , &GetString,
  626.     TAG_END);
  627.  
  628.   /* Create 'GetMBString' name */
  629.   if (strcmp(GetString, "GetMBString") == 0) 
  630.     GetMBString  = "GetMBString2";
  631.   else
  632.     GetMBString = "GetMBString";
  633.  
  634.   /* Create File Names */
  635.   remove_extend(FileName);
  636.   strncpy(GUIFile, FileName, 512);
  637.   add_extend(GUIFile, ".cpp");
  638.   strncpy(HeaderFile, FileName, 512);
  639.   add_extend(HeaderFile, ".h");
  640.   strncpy(Externals, FileName, 512);
  641.   strncat(Externals, "Extern", 512);
  642.   add_extend(Externals, ".h");
  643.   strncpy(Main, FileName, 512);
  644.   strncat(Main, "Main", 512);
  645.   add_extend(Main, ".cpp");
  646.  
  647.   /* Get Current Directory Name */
  648.   lock = Lock((APTR) "PROGDIR:", ACCESS_READ);
  649.   NameFromLock(lock, (APTR) MBDir, 512);
  650.   UnLock(lock);
  651. }
  652.  
  653. void WriteHeaderFile(void)
  654. {
  655.   char    *name;
  656.   char    buffer[600];
  657.   char    buffer2[600];
  658.  
  659.   if (Env)
  660.   {
  661.     strncpy(buffer, MBDir, 600);
  662.     AddPart((APTR) buffer, (APTR) "H++-Header", 512);
  663.     sprintf(buffer2, "copy \"%s\" \"%s\"", buffer, HeaderFile);
  664.     Execute((APTR) buffer2,0,0);
  665.   }
  666.   else
  667.     DeleteFile((APTR) HeaderFile);
  668.   file = fopen(HeaderFile, "a+");
  669.   if (file)
  670.   {
  671.     MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END);
  672.     fprintf(file, "struct Obj%s\n{\n", name);
  673.     WriteDeclarations(TYPEVAR_PTR);
  674.     WriteDeclarations(TYPEVAR_BOOL);
  675.     WriteDeclarations(TYPEVAR_INT);
  676.     WriteDeclarations(TYPEVAR_STRING);
  677.     WriteDeclarations(TYPEVAR_TABSTRING);
  678.     fprintf(file, "};\n\n");
  679.     if (Notifications)
  680.     {
  681.       WriteDeclarations(TYPEVAR_IDENT);
  682.       fprintf(file, "\n");
  683.     }
  684.     if (Env)
  685.     {
  686.       fprintf(file,"extern struct Obj%s * Create%s(void);\n", name, name);
  687.       fprintf(file,"extern void Dispose%s(struct Obj%s *);\n", name, name);
  688.     }
  689.     fclose(file);
  690.   }
  691. }
  692.  
  693. void WriteGUIFile(void)
  694. {
  695.   char    buffer[600];
  696.   char    buffer2[600];
  697.   char    *name;
  698.  
  699.   if (Env)
  700.   {
  701.     strncpy(buffer, MBDir, 600);
  702.     AddPart((APTR) buffer, (APTR) "C++-Header", 512);
  703.     sprintf(buffer2, "copy \"%s\" \"%s\"", buffer, GUIFile);
  704.     Execute((APTR) buffer2,0,0);
  705.   }
  706.   else 
  707.     DeleteFile((APTR) GUIFile);
  708.   if (file = fopen(GUIFile, "a+"))
  709.   {
  710.     if (Env)
  711.     {
  712.       MB_GetVarInfo(0, MUIB_VarName, &name, TAG_END);
  713.       fprintf(file, "\n#include \"%s\"\n", FilePart((APTR) HeaderFile));
  714.       if (ExternalExist) 
  715.         fprintf(file, "#include \"%s\"\n\n", FilePart((APTR) Externals));
  716.       if (Locale)
  717.       {
  718.     remove_extend(CatalogName);
  719.     fprintf(file, "#include \"%s_cat.h\"\n\n", FilePart((APTR) CatalogName) );
  720.     fprintf(file, "extern char* %s(int);\n", GetString);
  721.     fprintf(file, "\nstatic char *%s(int ref)\n{\n", GetMBString);
  722.     fprintf(file, "\tchar *aux;\n\n");
  723.     fprintf(file, "\taux = %s(ref);\n", GetString);
  724.     fprintf(file, "\tif (aux[1] == '\\0') return(&aux[2]);\n");
  725.     fprintf(file, "\telse                return(aux);\n}\n");
  726.       }
  727.       fprintf(file, "\nstruct Obj%s *Create%s(", name, name);
  728.       WriteParameters();
  729.       fprintf(file, ")\n");
  730.       fprintf(file, "{\n\tstruct Obj%s *MBObj;\n\n", name);
  731.     }
  732.     if (Declarations)
  733.     {
  734.       WriteDeclarations(TYPEVAR_LOCAL_PTR);
  735.       WriteInitialisations(TYPEVAR_HOOK);
  736.     }
  737.     if (Env) 
  738.       fprintf(file, "\n\tif (!(MBObj = (struct Obj%s *) AllocVec(sizeof(struct Obj%s), MEMF_PUBLIC|MEMF_CLEAR)))\n\t\treturn(NULL);\n", name, name);
  739.     if (Declarations)
  740.     {
  741.       WriteInitialisations(TYPEVAR_PTR);
  742.       WriteInitialisations(TYPEVAR_BOOL);
  743.       WriteInitialisations(TYPEVAR_INT);
  744.       WriteInitialisations(TYPEVAR_STRING);
  745.       WriteInitialisations(TYPEVAR_TABSTRING);
  746.     }
  747.     if (Code) WriteCode();
  748.     if (Env)
  749.     {
  750.       fprintf(file, "\n\tif (!MBObj->%s)\n\t{\n\t\tFreeVec(MBObj);", name);
  751.       fprintf(file, "\n\t\treturn(NULL);\n\t}\n");
  752.     }
  753.     if (Notifications) WriteNotify();
  754.     if (Env)
  755.     {
  756.       fprintf(file, "\n\treturn(MBObj);\n}\n");
  757.       fprintf(file, "\nvoid Dispose%s(struct Obj%s * MBObj)\n{\n", name, name);
  758.       fprintf(file, "\tMUI_DisposeObject( (Object *) MBObj->%s);\n", name);
  759.       fprintf(file, "\tFreeVec(MBObj);\n}\n");
  760.     }
  761.     fclose(file);
  762.   }
  763.   else 
  764.     printf("Unable to open GUI-File!\n");
  765. }
  766.  
  767. BOOL WriteExternalFile( void )
  768. {
  769.   int    i;
  770.   ULONG    length, type;
  771.   char    *varname;
  772.   struct FileInfoBlock *Info = AllocDosObject(DOS_FIB,NULL);
  773.   BOOL    result = FALSE;
  774.   BPTR    file2;
  775.   
  776.   if (file = fopen(Externals, "w+"))
  777.   {
  778.     /* write _EXTERNAL */
  779.     fprintf(file,"\n"); 
  780.     for(i=0;i<varnb;i++)
  781.     {
  782.       MB_GetVarInfo (i, MUIB_VarType, &type, MUIB_VarName, &varname, TAG_END);
  783.       if (type==TYPEVAR_EXTERNAL)
  784.     fprintf(file, "extern int %s;\n", varname);
  785.     }
  786.     /* write C++ function definition */
  787.     fprintf(file,"\n#ifdef cplusplus\n");
  788.     for(i=0;i<varnb;i++)
  789.     {
  790.       MB_GetVarInfo (i, MUIB_VarType, &type, MUIB_VarName, &varname, TAG_END);
  791.       if (type==TYPEVAR_HOOK)
  792.     fprintf(file, "extern void \"C\" %s(Object *);\n", varname);
  793.     }
  794.     /* write C function definition */
  795.     fprintf(file,"#else\n");
  796.     for(i=0;i<varnb;i++)
  797.     {
  798.       MB_GetVarInfo (i, MUIB_VarType, &type, MUIB_VarName, &varname, TAG_END);
  799.       if (type==TYPEVAR_HOOK)
  800.     fprintf(file, "extern void %s(Object *);\n", varname);
  801.     }
  802.     fprintf(file,"#endif\n");
  803.     fclose(file);
  804.   }
  805.   if (file2 = Open((APTR) Externals, MODE_OLDFILE))
  806.   {
  807.     ExamineFH(file2, Info);
  808.     Close(file2);
  809.     length = Info->fib_Size;
  810.     if (length == 0) 
  811.       DeleteFile((APTR) Externals);
  812.     else
  813.       result = TRUE;
  814.   }
  815.   FreeDosObject(DOS_FIB, Info);
  816.   return(result);
  817. }
  818.  
  819. void End(void)
  820. {
  821.   MB_Close();
  822.   if (MUIBBase) CloseLibrary(MUIBBase);
  823.   if (DOSBase) CloseLibrary(DOSBase);
  824. }
  825.  
  826. int main()
  827. {
  828.   MUIBBase = OpenLibrary((APTR) "muibuilder.library", 0);
  829.   DOSBase  = OpenLibrary((APTR) "dos.library", 0);
  830.  
  831.   if ((!MUIBBase)||(!DOSBase))
  832.   {
  833.     printf("Unable to open a library\n");
  834.     exit(20);
  835.   }
  836.  
  837.   if (!MB_Open())
  838.   {
  839.     printf("Unable to Get Temporary files !\n");
  840.     End();
  841.     exit(20);
  842.   }
  843.  
  844.   Init();
  845.   if (Declarations) WriteHeaderFile();
  846.   if (Env) ExternalExist = WriteExternalFile();
  847.   WriteGUIFile();
  848.  
  849.   End();
  850.   exit(0);
  851. }
  852.  
  853.